package com.woniu.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.bean.User;
import com.woniu.entity.dto.UserDTO;
import com.woniu.service.IUserService;
import io.swagger.annotations.Api;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("控制器")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @PostMapping("/add")
    public void add(@RequestBody User user) {
        boolean save = userService.save(user);
        System.out.println(save);
    }

    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable Integer id) {
        boolean b = userService.removeById(id);
        return b;
    }

    @PutMapping("/put")
    public boolean update(@RequestBody User user) {
        boolean update = userService.updateById(user);
        return update;
    }

    @PostMapping("/select")
    public IPage<User> selectPage(Integer currentPage, Integer pageSize, UserDTO userDTO) {
        IPage<User> page = userService.pageSelect(currentPage, pageSize, userDTO);
        return page;
    }

}
